package com.starblink.guangconfig.ui.part

import android.content.Context
import androidx.lifecycle.viewModelScope
import com.starblink.android.basic.bridge.BridgeCommand
import com.starblink.android.basic.bridge.BridgeUtil
import com.starblink.android.basic.config.GuangConfig
import com.starblink.android.basic.ext.toast
import com.starblink.android.basic.network.base.ApiSiteEnum
import com.starblink.android.basic.network.base.BaseApiCodeAndUrl
import com.starblink.android.basic.network.base.BaseApiConfig
import com.starblink.android.basic.network.base.BaseSiteSwitch
import com.starblink.android.basic.util.FlowCountDownTimer
import com.starblink.android.basic.util.bus.FlowBus
import com.starblink.android.basic.util.bus.FlowConst
import com.starblink.basic.storage.SkStorage
import com.starblink.basic.util.ActivityStackManage
import com.starblink.guangconfig.databinding.ActivityGuangUpConfigBinding
import com.starblink.guangconfig.ui.GuangUpConfigVM

object EnvironmentSwitchCiPart {
    private var open = BaseSiteSwitch.canSwitchPub()
    private var qaStatus = BaseSiteSwitch.isQaUse()


    fun handleVM(context: Context, m: GuangUpConfigVM, vb: ActivityGuangUpConfigBinding) {

        vb.environmentSwitchCi.ckPubUs.isChecked = open
        if (open) {
            vb.environmentSwitchCi.ckPubUs.text = "开启"
        } else {
            vb.environmentSwitchCi.ckPubUs.text = "关闭"
        }
        vb.environmentSwitchCi.ckPubUs.setOnClickListener {
            if (open) {
                open = false
                vb.environmentSwitchCi.ckPubUs.text = "关闭"
            } else {
                open = true
                vb.environmentSwitchCi.ckPubUs.text = "开启"
            }
            vb.environmentSwitchCi.ckPubUs.isChecked = open
            BaseSiteSwitch.setSwitchPub(open)
            FlowBus.boolFlowBusNotify(FlowConst.SWITCH_SITE_CI_CTL, bool = open)
        }

        ////


        vb.environmentSwitchCi.ckNoInitSite.isChecked = qaStatus
        if (qaStatus) {
            vb.environmentSwitchCi.ckNoInitSite.text = "开启"
        } else {
            vb.environmentSwitchCi.ckNoInitSite.text = "关闭"
        }
        vb.environmentSwitchCi.ckNoInitSite.setOnClickListener {
            if (qaStatus) {
                qaStatus = false
                vb.environmentSwitchCi.ckNoInitSite.text = "关闭"
            } else {
                qaStatus = true
                vb.environmentSwitchCi.ckNoInitSite.text = "开启"
            }
            vb.environmentSwitchCi.ckNoInitSite.isChecked = qaStatus

            BaseSiteSwitch.setQaUse(qaStatus)
        }

    }


}